home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / lists / src / insert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.4 KB  |  103 lines

  1. /*
  2.     (C) 1995 AROS - The Amiga Replacement OS
  3.     $Id: insert.c 1.1 1995/11/05 22:49:09 digulla Exp digulla $
  4.     $Log: insert.c $
  5.  * Revision 1.1  1995/11/05  22:49:09  digulla
  6.  * Initial revision
  7.  *
  8.     Desc:
  9.     Lang: english
  10. */
  11. #include "exec_intern.h"
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME */
  16.     #include <exec/lists.h>
  17.     #include <clib/exec_protos.h>
  18.  
  19.     __AROS_LH3I(void, Insert,
  20.  
  21. /*  SYNOPSIS */
  22.     __AROS_LA(struct List *, list, A0),
  23.     __AROS_LA(struct Node *, node, A1),
  24.     __AROS_LA(struct Node *, pred, A2),
  25.  
  26. /*  LOCATION */
  27.     struct SysBase *, SysBase, 39, Exec)
  28.  
  29. /*  FUNCTION
  30.     Insert Node node after pred in list.
  31.  
  32.     INPUTS
  33.     list - The list to insert the node into
  34.     node - This node is to be inserted
  35.     pred - Insert after this node. If this is NULL, node is inserted
  36.         as the first node (same as AddHead()).
  37.  
  38.     RESULT
  39.  
  40.     NOTES
  41.  
  42.     EXAMPLE
  43.     struct List * list;
  44.     struct Node * pred, * node;
  45.  
  46.     // Insert Node node as second node in list
  47.     pred = GetHead (list);
  48.     Insert (list, node, pred);
  49.  
  50.     BUGS
  51.  
  52.     SEE ALSO
  53.     AddHead(), AddTail(), Enqueue(), RemHead(), Remove(), RemTail(),
  54.     "AROS: Exec Lists".
  55.  
  56.     INTERNALS
  57.  
  58.     HISTORY
  59.     26-08-95    digulla created after EXEC-Routine
  60.     26-10-95    digulla adjusted to new calling scheme
  61.  
  62. ******************************************************************************/
  63. {
  64.     assert (node);
  65.     assert (list);
  66.  
  67.     /* If we have a node to insert behind... */
  68.     if (pred)
  69.     {
  70.     /*
  71.         Our successor is the successor of the node we add ourselves
  72.         behind and our predecessor is just the node itself.
  73.     */
  74.     node->ln_Succ = pred->ln_Succ;
  75.     node->ln_Pred = pred;
  76.  
  77.     /*
  78.         We are the predecessor of the successor of our predecessor
  79.         (What ? blblblb... ;) and of out predecessor itself.
  80.         Note that here the sequence is quite important since
  81.         we need ln_Succ in the first expression and change it in
  82.         the second.
  83.     */
  84.     pred->ln_Succ->ln_Pred = node;
  85.     pred->ln_Succ = node;
  86.     }
  87.     else
  88.     {
  89.     /*
  90.         add at the top of the list. I do not use AddHead() here but
  91.         write the code twice for two reasons: 1. The code is small and
  92.         quite prone to errors and 2. If I would call AddHead(), it
  93.         would take almost as long to call the function as the execution
  94.         would take yielding 100% overhead.
  95.     */
  96.     node->ln_Succ           = list->lh_Head;
  97.     node->ln_Pred           = (struct Node *)&list->lh_Head;
  98.     list->lh_Head->ln_Pred = node;
  99.     list->lh_Head           = node;
  100.     }
  101. } /* Insert */
  102.  
  103.